home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-02 / sort2.zip / SORTARGS.INC < prev    next >
Text File  |  1993-01-04  |  3KB  |  61 lines

  1. procedure arguments;
  2. { handles the command line parameters for SORT }
  3. { Copyright 1988,1989, by J. W. Rider }
  4.  
  5. { Upon exit, the global variable "parmcount" is the index
  6.   of the first non-switch parameter }
  7.  
  8. { The general approach is to permit both "/" and "-" as
  9.   valid switch indicators.  With "/", only a single switch
  10.   can be specified, but the options can be packed together
  11.   without any spacing. ("/a/b/c" is okay and means the same as "/a /b /c",
  12.   but "/abc" is not.)  With "-", multiple switches can be specified but
  13.   individual "-" must be preceded by a space. ("-abc" is okay and means
  14.   the same as "-a -b -c", but "-a-b-c" is invalid.) }
  15.  
  16. { Unlike Unix implementations, either upper or lower case characters
  17.   can be used for switches. }
  18.  
  19. var i,j:integer; parm:string;
  20. begin i:=1;
  21.  
  22. { handle the option switches }
  23. if paramcount>0 then begin
  24.    parm:=paramstr(i);
  25.    while ((length(parm)>1) and (parm[1] in ['-','/'])) do begin
  26.  
  27.            if parm[2] in ['b','B'] then ignoreblanks:=true
  28.       else if parm[2] in ['c','C'] then sensecase:=not defaultcase
  29.       else if parm[2] in ['d','D'] then ancase:=true
  30.       else if parm[2] in ['f','F'] then usefields:=true
  31.       else if parm[2] in ['h','H'] then helponly:=true
  32.       else if parm[2] in ['k','K'] then keysonly:=true
  33.       else if parm[2] in ['n','N'] then sortnumeric:=true
  34.       else if parm[2] in ['r','R'] then reversed:=true
  35.       else if parm[2] in ['t','T'] then
  36.            if length(parm)>2 then begin
  37.               delimset:=delimset + [ parm[3] ];
  38.               parm:=copy(parm,1,2)+copy(parm,4,255); end
  39.            else delimset:=delimset+[^I,' ']
  40.       else if parm[2] in ['u','U'] then unique:=true
  41.       else begin
  42.          parm[1]:='/'; { needed for option chaining to work properly }
  43.          j:=trunc(bval(copy(parm,2,length(parm)-1)));
  44.          if (j>=1) and (j<255) then
  45.             if keycol=0 then keycol:=j
  46.             else if keycol2=0 then keycol2:=j; end;
  47.  
  48.       if parm[1]='/' then begin
  49.          j:=pos('/',copy(parm,2,length(parm)-1));
  50.          if j>0 then begin
  51.             parm:=copy(parm,j+1,length(parm)-j);
  52.             if length(parm)<1 then begin
  53.                inc(i); parm:=paramstr(i); end; end
  54.          else begin inc(i); parm:=paramstr(i); end; end
  55.       else begin parm:='-'+copy(parm,3,length(parm)-2);
  56.          if length(parm)<2 then begin
  57.             inc(i); parm:=paramstr(i); end; end; end; end;
  58.  
  59. parmcount:=i; end; {procedure arguments}
  60.  
  61.